# user：hp
# web自动化阶段 2022/6/3
# 时间 0:37
"""所有动态函数存放模板"""
from random import randint

from api.http_api import UnifyApi
from utility.mysql_api import MysqlApi


def get_mobile(n=10):
    """
    获得随机手机号
    :return:
    """
    mobile = '1'
    for _ in range(n):
        mobile += str(randint(0, 9))
    return mobile

token_ = None
def get_token(is_init=False):
    """
    获取令牌
    :param is_init: 是否刷新令牌
    :return:
    """
    global token_
    if not token_ or is_init:
        dicts = {'method': 'post', 'url': 'http://ihrm-test.itheima.net/api/sys/login',
                 'json': {'mobile': '13800000002', 'password': '123456'}}
        token_ = UnifyApi.send_requests(**dicts).json()['data']
    return token_

# mysql = MysqlApi()
# def get_id_mysql(name):
#     """
#     根据名字从数据库获取id
#     :param name:
#     :return:
#     """
#     a = mysql.select('select id from bs_user where username="{}"'.format(name))
#     return a[0]

def get_number():
    """
    获取10~99的随机数
    :return:
    """
    return randint(10, 99)


if __name__ == '__main__':
    print(get_token())

